/**
 * 
 */
package com.pks.insurance.dao.impl;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.pks.insurance.dao.VehicleDAO;
import com.pks.insurance.dto.VehicleDto;
import com.pks.insurance.util.HibernateUtil;

/**
 * Implementation class for VehicleDAO.
 * 
 * @author Pankaj Soni
 * 
 */
public class VehicleDAOImpl implements VehicleDAO {
	private static final Logger LOGGER = Logger.getLogger(VehicleDAOImpl.class);

	/**
	 * @see com.pks.autoInsurance.dao.VehicleDAO#updateVehicle(com.pks.autoInsurance.dto.VehicleDto)
	 */
	@Override
	public final boolean updateVehicle(final VehicleDto vehicle) {
		LOGGER.debug("begin");
		boolean result = false;
		Session session = HibernateUtil.getSession();
		Transaction transaction = null;
		try {
			transaction = session.beginTransaction();
			session.saveOrUpdate(vehicle);
			transaction.commit();
			result = true;
		} catch (HibernateException e) {
			transaction.rollback();
			LOGGER.error(e.getMessage());
		} finally {
			session.flush();
			session.close();
		}
		LOGGER.info("result: " + result);
		LOGGER.debug("end");
		return result;
	}
}
